Ignore EPERM when scanning for packages
authorAlex Crichton <alex@alexcrichton.com>
Fri, 17 Oct 2014 21:02:16 +0000 (14:02 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 17 Oct 2014 21:02:16 +0000 (14:02 -0700)
We won't make much progress reporting the error back up the chain, so we may as
well carry on!

src/cargo/ops/cargo_read_manifest.rs
tests/test_cargo_compile.rs

index 19615f60eeb4c3685a983e808ca7656f115b60fa..1b73726829c6719b6d60ab0e47f54c053c1655eb 100644 (file)
@@ -1,9 +1,9 @@
 use std::collections::HashSet;
-use std::io::{File, fs};
+use std::io::{mod, File, fs};
 use std::io::fs::PathExtensions;
 
 use core::{Package,Manifest,SourceId};
-use util::{mod, CargoResult, human};
+use util::{mod, CargoResult, human, CargoError};
 use util::important_paths::find_project_manifest_exact;
 use util::toml::{Layout, project_layout};
 
@@ -61,7 +61,14 @@ fn walk(path: &Path, is_root: bool,
             return Ok(());
         }
 
-        for dir in try!(fs::readdir(path)).iter() {
+        // Ignore any permission denied errors because temporary directories
+        // can often have some weird permissions on them.
+        let dirs = match fs::readdir(path) {
+            Ok(dirs) => dirs,
+            Err(ref e) if e.kind == io::PermissionDenied => return Ok(()),
+            Err(e) => return Err(e.box_error()),
+        };
+        for dir in dirs.iter() {
             try!(walk(dir, false, |a, x| callback(a, x)))
         }
     }
index b0ff9d7165d60b025200cf424f37199d425c1c5b..b6077f30fcbd9ee9c922e088cdb1cf34e51c06aa 100644 (file)
@@ -1,4 +1,4 @@
-use std::io::{fs, TempDir, File};
+use std::io::{mod, fs, TempDir, File};
 use std::os;
 use std::path;
 
@@ -1662,3 +1662,18 @@ test!(recompile_space_in_name {
     assert_that(foo.process(cargo_dir().join("cargo")).arg("build"),
                 execs().with_status(0).with_stdout(""));
 })
+
+test!(ignore_bad_directories {
+    let foo = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.0"
+            authors = []
+        "#)
+        .file("src/lib.rs", "");
+    foo.build();
+    fs::mkdir(&foo.root().join("tmp"), io::USER_EXEC ^ io::USER_EXEC).unwrap();
+    assert_that(foo.process(cargo_dir().join("cargo")).arg("build"),
+                execs().with_status(0));
+})